package com.smart.servlet;
import com.smart.dao.DBoperator1;
import com.smart.dao.DBoperator2;
import com.smart.dao.DBoperator3;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.String;
@WebServlet( name = "Servlet",urlPatterns ="/Servlet")
/*获取表单用户登录的信息 */
public class Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name=request.getParameter("loginuser");
        String password=request.getParameter("loginpwd");
        String zhiye = request.getParameter("zhiwei");
        DBoperator1 dBoperator1=new DBoperator1();
        DBoperator2 dBoperator2=new DBoperator2();
        DBoperator3 dBoperator3=new DBoperator3();
        System.out.println(name);
        System.out.println(password);
        System.out.println(zhiye);
        boolean a=dBoperator3.insert(name,password);
        boolean b=dBoperator1.insert(name,password);
        boolean c=dBoperator2.insert(name,password);
        System.out.println(zhiye.equals("3"));
        if(b&&zhiye.equals("3")){//老师的登录
            request.getRequestDispatcher("head.html").forward(request,response);
            System.out.println("跳转head成功");
        }
        if(c&&zhiye.equals("1")){//学生的登录
            request.getRequestDispatcher("head.html").forward(request,response);
            System.out.println("跳转head成功");
        }
        if(a&&zhiye.equals("2")){//班长的登录
            request.getRequestDispatcher("head.html").forward(request,response);
            System.out.println("跳转head成功");
        }
        else{
            request.getRequestDispatcher("loginerror.html").forward(request,response);
            System.out.println("跳转error成功");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
